home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / usr_-_Usr_Files / INCLUDE / STDLIB.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  15KB  |  418 lines

  1. /* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    ANSI Standard: 4.10 GENERAL UTILITIES    <stdlib.h>
  21.  */
  22.  
  23. /* Don't include it for K&R C. */
  24. #if ((defined (__STDC__) && __STDC__) || defined (__cplusplus)) \
  25.     && !defined(_STDLIB_H)
  26.  
  27. #define    _STDLIB_H    1
  28. #include <features.h>
  29.  
  30. /* Get size_t, wchar_t and NULL from <stddef.h>.  */
  31. #define    __need_size_t
  32. #define    __need_wchar_t
  33. #define    __need_NULL
  34. #include <stddef.h>
  35.  
  36. /* Don't ask me why. H.J. */
  37. #ifndef NULL
  38. #define NULL ((void *)0)
  39. #endif
  40.  
  41. #define    __need_Emath
  42. #include <errno.h>
  43.  
  44. __BEGIN_DECLS
  45.  
  46. /* Returned by `div'.  */
  47. typedef struct
  48.   {
  49.     int quot;            /* Quotient.  */
  50.     int rem;            /* Remainder.  */
  51.   } div_t;
  52.  
  53. /* Returned by `ldiv'.  */
  54. typedef struct
  55.   {
  56.     long int quot;        /* Quotient.  */
  57.     long int rem;        /* Remainder.  */
  58.   } ldiv_t;
  59.  
  60.  
  61. /* The largest number rand will return (same as INT_MAX).  */
  62. #ifndef RAND_MAX
  63. #define    RAND_MAX    2147483647
  64. #endif
  65.  
  66.  
  67. /* We define these the same for all machines.
  68.    Changes from this to the outside world should be done in `_exit'.  */
  69. #define    EXIT_FAILURE    1    /* Failing exit status.  */
  70. #define    EXIT_SUCCESS    0    /* Successful exit status.  */
  71.  
  72.  
  73. /* Maximum length of a multibyte character in the current locale.
  74.    This is just one until the fancy locale support is finished.  */
  75. #define    MB_CUR_MAX    1
  76.  
  77.  
  78. /* Convert a string to a floating-point number.  */
  79. extern double atof __P ((__const char *__nptr));
  80. /* Convert a string to an integer.  */
  81. extern int atoi __P ((__const char *__nptr));
  82. /* Convert a string to a long integer.  */
  83. extern long int atol __P ((__const char *__nptr));
  84. #if __GNUC__ >= 2 && defined(__USE_GNU) && !defined(__STRICT_ANSI__)
  85. /* Convert a string to a long long integer.  */
  86. extern long long int atoq __P((__const char *__nptr));
  87. #endif
  88.  
  89. /* Convert a string to a single precision floating-point number.  */
  90. extern float strtof __P ((__const char *__nptr, char **__endptr));
  91. /* Convert a string to a double precision floating-point number.  */
  92. extern double strtod __P ((__const char *__nptr, char **__endptr));
  93. #if __GNUC__ >= 2 && defined(__USE_GNU)
  94. /* Convert a string to an extended precision floating-point number.  */
  95. extern __long_double_t strtold __P ((__const char *__nptr, char **__endptr));
  96. #endif
  97. /* Convert a string to a long integer.  */
  98. extern long int strtol __P ((__const char *__nptr, char **__endptr,
  99.                  int __base));
  100. /* Convert a string to an unsigned long integer.  */
  101. extern unsigned long int strtoul __P ((__const char *__nptr,
  102.                        char **__endptr, int __base));
  103. #if __GNUC__ >= 2 && defined(__USE_GNU) && !defined(__STRICT_ANSI__)
  104. /* Convert a string to a long long integer.  */
  105. extern long long int strtoq __P((__const char *__nptr, char **__endptr,
  106.                 int __base));
  107. /* Convert a string to an unsigned long long integer.  */
  108. extern unsigned long long int strtouq __P((__const char *__nptr,
  109.                     char **__endptr, int __base));
  110. #endif
  111.  
  112. /* The internal entry points for `strtoX' take an extra flag argument
  113.    saying whether or not to parse locale-dependent number grouping.  */
  114.  
  115. extern double __strtod_internal (__const char *__nptr,
  116.                  char **__endptr, int __group);
  117. extern float __strtof_internal (__const char *__nptr, char **__endptr,
  118.                 int __group);
  119. extern __long_double_t __strtold_internal (__const char *__nptr,
  120.                        char **__endptr, int __group);
  121. extern long int __strtol_internal (__const char *__nptr, char **__endptr,
  122.                    int __base, int __group);
  123. extern unsigned long int __strtoul_internal (__const char *__nptr,
  124.                          char **__endptr, int __base,
  125.                          int __group);
  126. #if __GNUC__ >= 2 && defined(__USE_GNU) && !defined(__STRICT_ANSI__)
  127. extern long long int __strtoq_internal (__const char *__nptr, char **__endptr,
  128.                     int __base, int __group);
  129. extern unsigned long long int __strtouq_internal (__const char *__nptr,
  130.                           char **__endptr, int __base,
  131.                           int __group);
  132. #endif
  133.  
  134. #if defined (__OPTIMIZE__) && __GNUC__ >= 2 && !defined(__STRICT_ANSI__)
  135. /* Define inline functions which call the internal entry points.  */
  136.  
  137. extern __inline double strtod (__const char *__nptr, char **__endptr)
  138. { return __strtod_internal (__nptr, __endptr, 0); }
  139. extern __inline long int strtol (__const char *__nptr,
  140.                  char **__endptr, int __base)
  141. { return __strtol_internal (__nptr, __endptr, __base, 0); }
  142. extern __inline unsigned long int strtoul (__const char *__nptr,
  143.                        char **__endptr, int __base)
  144. { return __strtoul_internal (__nptr, __endptr, __base, 0); }
  145.  
  146. extern __inline float strtof (__const char *__nptr, char **__endptr)
  147. { return __strtof_internal (__nptr, __endptr, 0); }
  148. extern __inline __long_double_t strtold (__const char *__nptr, char **__endptr)
  149. { return __strtold_internal (__nptr, __endptr, 0); }
  150.  
  151. #if defined(__USE_GNU) && !defined(__STRICT_ANSI__)
  152. extern __inline long long int strtoq (__const char *__nptr, char **__endptr,
  153.                                       int __base)
  154. { return __strtoq_internal (__nptr, __endptr, __base, 0); }
  155. extern __inline unsigned long long int strtouq (__const char *__nptr,
  156.                                             char **__endptr, int __base)
  157. { return __strtouq_internal (__nptr, __endptr, __base, 0); }
  158. #endif
  159.  
  160. extern __inline double atof (__const char *__nptr)
  161. { return strtod(__nptr, (char **) NULL); }
  162. extern __inline int atoi (__const char *__nptr)
  163. { return (int) strtol (__nptr, (char **) NULL, 10); }
  164. extern __inline long int atol (__const char *__nptr)
  165. { return strtol (__nptr, (char **) NULL, 10); }
  166. #if defined(__USE_GNU) && !defined(__STRICT_ANSI__)
  167. extern __inline long long int atoq (__const char *__nptr)
  168. { return strtoq(__nptr, (char **) NULL, 10); }
  169. #endif
  170. #endif /* Optimizing GCC >=2.  */
  171.  
  172.  
  173. /* Return a random integer between 0 and RAND_MAX inclusive.  */
  174. extern int rand __P ((void));
  175. /* Seed the random number generator with the given number.  */
  176. extern void srand __P ((unsigned int __seed));
  177.  
  178. /* These are the functions that actually do things.  The `random', `srandom',
  179.    `initstate' and `setstate' functions are those from BSD Unices.
  180.    The `rand' and `srand' functions are required by the ANSI standard.
  181.    We provide both interfaces to the same random number generator.  */
  182. /* Return a random long integer between 0 and RAND_MAX inclusive.  */
  183. extern long int __random __P ((void));
  184. /* Seed the random number generator with the given number.  */
  185. extern void __srandom __P ((unsigned int __seed));
  186.  
  187. /* Initialize the random number generator to use state buffer STATEBUF,
  188.    of length STATELEN, and seed it with SEED.  Optimal lengths are 8, 16,
  189.    32, 64, 128 and 256, the bigger the better; values less than 8 will
  190.    cause an error and values greater than 256 will be rounded down.  */
  191. extern __ptr_t __initstate __P ((unsigned int __seed, __ptr_t __statebuf,
  192.                  size_t __statelen));
  193. /* Switch the random number generator to state buffer STATEBUF,
  194.    which should have been previously initialized by `initstate'.  */
  195. extern __ptr_t __setstate __P ((__ptr_t __statebuf));
  196.  
  197. #ifdef    __USE_BSD
  198. extern long int random __P ((void));
  199. extern void srandom __P ((unsigned int __seed));
  200. extern __ptr_t initstate __P ((unsigned int __seed, __ptr_t __statebuf,
  201.                    size_t __statelen));
  202. extern __ptr_t setstate __P ((__ptr_t __statebuf));
  203.  
  204. #if defined (__OPTIMIZE__) && __GNUC__ >= 2 && !defined(__STRICT_ANSI__)
  205. extern __inline long int random (void)
  206. { return __random(); }
  207. extern __inline void srandom (unsigned int __seed)
  208. { __srandom(__seed); }
  209. extern __inline __ptr_t initstate (unsigned int __seed,
  210.                    __ptr_t __statebuf, size_t __statelen)
  211. { return __initstate (__seed, __statebuf, __statelen); }
  212. extern __inline __ptr_t setstate (__ptr_t __statebuf)
  213. { return __setstate (__statebuf); }
  214. #endif /* Optimizing GCC >=2.  */
  215. #endif /* Use BSD.  */
  216.  
  217.  
  218. /* Allocate SIZE bytes of memory.  */
  219. extern __ptr_t malloc __P ((size_t __size));
  220. /* Re-allocate the previously allocated block
  221.    in __ptr_t, making the new block SIZE bytes long.  */
  222. extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size));
  223. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
  224. extern __ptr_t calloc __P ((size_t __nmemb, size_t __size));
  225. /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
  226. extern void free __P ((__ptr_t __ptr));
  227.  
  228. #ifdef    __USE_MISC
  229. /* Free a block.  An alias for `free'.    (Sun Unices).  */
  230. extern void cfree __P ((__ptr_t __ptr));
  231. #endif /* Use misc.  */
  232.  
  233. #if defined(__USE_GNU) || defined(__USE_BSD) || defined(__USE_MISC)
  234. #include <alloca.h>
  235. #endif /* Use GNU, BSD, or misc.  */
  236.  
  237. #ifdef    __USE_BSD
  238. /* Allocate SIZE bytes on a page boundary.  The storage cannot be freed.  */
  239. extern __ptr_t valloc __P ((size_t __size));
  240. #endif
  241.  
  242.  
  243. /* Abort execution and generate a core-dump.  */
  244. extern __NORETURN void abort __P ((void));
  245.  
  246.  
  247. /* Register a function to be called when `exit' is called.  */
  248. extern int atexit __P ((void (*__func) (void)));
  249.  
  250. #ifdef    __USE_MISC
  251. /* Register a function to be called with the status
  252.    given to `exit' and the given argument.  */
  253. extern int on_exit __P ((void (*__func) (int __status, __ptr_t __arg),
  254.              __ptr_t __arg));
  255. #endif
  256.  
  257. /* Call all functions registered with `atexit' and `on_exit',
  258.    in the reverse of the order in which they were registered
  259.    perform stdio cleanup, and terminate program execution with STATUS.  */
  260. extern __NORETURN void exit __P ((int __status));
  261.  
  262.  
  263. /* Return the value of envariable NAME, or NULL if it doesn't exist.  */
  264. extern char *getenv __P ((__const char *__name));
  265.  
  266. #if defined(__USE_SVID) || defined(__USE_BSD)
  267. /* The SVID says this is in <stdio.h>, but this seems a better place.    */
  268. /* Put STRING, which is of the form "NAME=VALUE", in the environment.
  269.    If there is no `=', remove NAME from the environment.  */
  270. extern int putenv __P ((__const char *__string));
  271. #endif
  272.  
  273. #ifdef    __USE_BSD
  274. /* Set NAME to VALUE in the environment.
  275.    If REPLACE is nonzero, overwrite an existing value.  */
  276. extern int setenv __P ((__const char *__name, __const char *__value,
  277.             int __replace));
  278. #endif
  279.  
  280. /* Execute the given line as a shell command.  */
  281. extern int system __P ((__const char *__command));
  282.  
  283.  
  284. #ifndef __COMPAR_FN_T
  285. #define __COMPAR_FN_T
  286. /* Shorthand for type of comparison functions.  */
  287. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  288. #endif
  289.  
  290. #ifdef    __USE_GNU
  291. typedef __compar_fn_t comparison_fn_t;
  292. #endif
  293.  
  294. /* Do a binary search for KEY in BASE, which consists of NMEMB elements
  295.    of SIZE bytes each, using COMPAR to perform the comparisons.  */
  296. extern __ptr_t bsearch __P ((__const __ptr_t __key, __const __ptr_t __base,
  297.                  size_t __nmemb, size_t __size,
  298.                  __compar_fn_t __compar));
  299.  
  300. /* Sort NMEMB elements of BASE, of SIZE bytes each,
  301.    using COMPAR to perform the comparisons.  */
  302. extern void qsort __P ((__ptr_t __base, size_t __nmemb, size_t __size,
  303.             __compar_fn_t __compar));
  304.  
  305.  
  306. #ifndef    __CONSTVALUE
  307. #ifdef    __GNUC__
  308. /* The `const' keyword tells GCC that a function's return value is
  309.    based solely on its arguments, and there are no side-effects.  */
  310. #define    __CONSTVALUE    __const
  311. #else
  312. #define    __CONSTVALUE
  313. #endif /* GCC.  */
  314. #endif /* __CONSTVALUE not defined.  */
  315.  
  316. /* Return the absolute value of X.  */
  317. extern __CONSTVALUE int abs __P ((int __x));
  318. extern __CONSTVALUE long int labs __P ((long int __x));
  319.  
  320.  
  321. /* Return the `div_t' or `ldiv_t' representation
  322.    of the value of NUMER over DENOM. */
  323. /* GCC may have built-ins for these someday.  */
  324. extern __CONSTVALUE div_t div __P ((int __numer, int __denom));
  325. extern __CONSTVALUE ldiv_t ldiv __P ((long int __numer, long int __denom));
  326.  
  327.  
  328. /* Return the length of the multibyte character
  329.    in S, which is no longer than N.  */
  330. extern int mblen __P ((__const char *__s, size_t __n));
  331. /* Return the length of the given multibyte character,
  332.    putting its `wchar_t' representation in *PWC.  */
  333. extern int mbtowc __P ((wchar_t * __pwc, __const char *__s, size_t __n));
  334. /* Put the multibyte character represented
  335.    by WCHAR in S, returning its length.  */
  336. extern int wctomb __P ((char *__s, wchar_t __wchar));
  337.  
  338. #if defined (__OPTIMIZE__) && __GNUC__ >= 2 && !defined(__STRICT_ANSI__)
  339. extern __inline int mblen (__const char *__s, size_t __n)
  340. { return mbtowc ((wchar_t *) NULL, __s, __n); }
  341. #endif /* Optimizing GCC >=2.  */
  342.  
  343.  
  344. /* Convert a multibyte string to a wide char string.  */
  345. extern size_t mbstowcs __P ((wchar_t * __pwcs, __const char *__s, size_t __n));
  346. /* Convert a wide char string to multibyte string.  */
  347. extern size_t wcstombs __P ((char *__s, __const wchar_t * __pwcs, size_t __n));
  348.  
  349. /* Some ill behaved applications don't expect malloc (0) returns
  350.  * NULL. We put this hack here for them. For good behaved
  351.  * applications, we should define __MALLOC_0_RETURNS_NULL.
  352.  */
  353.  
  354. /* For backward compatibilities and X11R5 */
  355. #if (defined(MALLOC_0_RETURNS_NULL) || defined(NO_FIX_MALLOC)) \
  356.     && !defined(__MALLOC_0_RETURNS_NULL)
  357. #define __MALLOC_0_RETURNS_NULL
  358. #endif
  359.  
  360. /* We have changed malloc () to take malloc (0). */
  361. #if 0 && !defined(__MALLOC_0_RETURNS_NULL)
  362. static __inline void* __gnu_calloc (size_t __nmemb, size_t __n)
  363. {
  364.   return calloc (__nmemb ? __nmemb : 1, __n ? __n : 1);
  365. }
  366.  
  367. static __inline void* __gnu_malloc (size_t __n)
  368. {
  369.   return malloc (__n ? __n : 1);
  370. }
  371.  
  372. #define calloc        __gnu_calloc
  373. #define malloc        __gnu_malloc
  374.  
  375. #endif
  376.  
  377. /* I added the followings to Linux. H.J. */
  378. #if defined(__USE_MISC)
  379.  
  380. extern char **environ;
  381. extern char **__environ;
  382.  
  383. extern char*    ecvt __P((double __value, size_t __ndigit, int *__decpt,
  384.             int *__sign));
  385. extern char*    fcvt __P((double __value, size_t __ndigit, int *__decpt,
  386.             int *__sign));
  387. extern char*    gcvt __P((double __value, size_t __ndigit, char *__buf));
  388.  
  389. extern double    drand48 __P((void));
  390. extern double    erand48 __P((unsigned short int __xsubi[3]));
  391. extern long int    lrand48 __P((void));
  392. extern long int    nrand48 __P((unsigned short int __xsubi[3]));
  393. extern long int    mrand48 __P((void));
  394. extern long int    jrand48 __P((unsigned short int __xsubi[3]));
  395. extern void    srand48 __P((long int __seedval));
  396. extern unsigned short int
  397.             *seed48 __P((unsigned short int __seed16v[3]));
  398. extern void    lcong48 __P((unsigned short int __param[7]));
  399.  
  400. extern int    setenv __P((__const char *__name, __const char *__value,
  401.             int __overwrite));
  402. extern void    unsetenv __P((__const char *__name));
  403.  
  404. struct qelem {
  405.   struct qelem *q_forw;
  406.   struct qelem *q_back;
  407.   char q_data[1];
  408. };
  409.  
  410. extern void insque __P((struct qelem *__elem, struct qelem *__prev));
  411. extern void remque __P((struct qelem *__elem));
  412.  
  413. #endif    /* __USE_MISC */
  414.  
  415. __END_DECLS
  416.  
  417. #endif /* stdlib.h  */
  418.